#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[100005],n;
ll ans;
void f(int dep,int h,int l,ll sum){
    if(dep>n){
        ans=max(ans,sum);
        return ;
    }
    if(a[h]!=a[dep]) f(dep+1,dep,l,sum);
    else f(dep+1,dep,l,sum+1ll*a[h]);
    if(a[l]!=a[dep]) f(dep+1,h,dep,sum);
    else f(dep+1,h,dep,sum+1ll*a[l]);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        ans=0;
        a[0]=0;
        f(0,0,0,0);
        cout<<ans<<'\n';
    }
    return 0;
}
//color
